﻿using System;
using System.Linq;
using System.Threading;
using CcrFlows.Internal.Stages;
using NUnit.Framework;
using Microsoft.Ccr.Core;

namespace Test.CcrFlows
{
    [TestFixture]
    public class testScatterStage
    {
        [Test]
        public void Create_scatter_stage()
        {
            var scatter = new ScatterStage<int, string>((i, ps) => {
                                                                     Console.WriteLine("process {0}", i);
                                                                     ps.Post(i + "x");
                                                                     Thread.Sleep(300);
                                                                   });

            const int N_ELEMENTS = 5;
            for (int i = 0; i < N_ELEMENTS; i++) scatter.Input.First().PostUnknownType(i);

            for(int i=0; i<N_ELEMENTS; i++)
            {
                string t;
                Assert.IsTrue(((Port<string>)scatter.Output.First()).WaitFor(1000, out t));
                Console.WriteLine("received {0}", t);
            }
        }
    }
}
